package com.hwz.controller.user;

import com.hwz.dto.ShoppingCartDTO;
import com.hwz.entity.ShoppingCart;
import com.hwz.result.Result;
import com.hwz.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Lenovo]
 * @version : [v1.0]
 * @createTime : [2024/3/19 17:21]
 */
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<ShoppingCart>> getShoppingCartList(){
        return Result.success(shoppingCartService.getShoppingCartList());
    }

    @PostMapping("/sub")
    public Result delShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.delShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @DeleteMapping("/clean")
    public Result cleanShoppingCart() {
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
}
